/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.BUS;

import Server.DAO.DatabaseAccess;
import Server.DTO.Table;
import java.io.File;

/**
 *
 * @author Trung
 */
public class DatabaseBUS {
   private DatabaseAccess dbAccess = new DatabaseAccess();
    
    ///Create a file contain design table
    public void newTable(String path){
        File table = new File(path);
        
        if(!table.exists()){
            table.mkdir();            
        }
    }
    
    ///Call function from DesignTableDAO to save design table
    public void saveDesignTable(Table table, String path){
        for(int i = 0; i < path.length(); i++){
            if(path.charAt(i) == '.'){
                dbAccess.writeTableToFile(table, path);
                return;
            }
        }
        
        String filePath =  path + "\\" + table.getName();
        newTable(filePath);
        dbAccess.writeTableToFile(table, filePath);

    }
    
    ///Call function from DesignTableDAO to get design table
    public Table readDesignTable(String designPath){
        return dbAccess.readTableFromFile(designPath);
    } 
}
